package com.socool.sinofaith.ui;

import com.socool.sinofaith.R;
import com.socool.sinofaith.SocoolApplication;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

/**
 * 问卷追踪Fragment
 * @author YD
 *
 */
public class QuestionFragment extends Fragment implements View.OnClickListener {

	private Button submittedTaskButton, auditingTaskButton;
	private QuestionSubmittedFragment submittedFragment;
	private AuditRefusedFragment refusedFragment;
	private FragmentManager fragmentManager;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_question, null);
		SocoolApplication.addActivity(this.getActivity());
		submittedTaskButton = (Button) view.findViewById(R.id.submittedTaskButton);
		auditingTaskButton = (Button) view.findViewById(R.id.auditingTaskButton);
		submittedTaskButton.setOnClickListener(this);
		auditingTaskButton.setOnClickListener(this);
		submittedFragment = new QuestionSubmittedFragment();
		refusedFragment = new AuditRefusedFragment();

		fragmentManager = this.getFragmentManager();
		FragmentTransaction transaction = fragmentManager.beginTransaction();
		transaction.replace(R.id.myfragcontent, submittedFragment);
		transaction.commit();
		
		return view;
	}

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.submittedTaskButton:
			submittedTaskButton.setBackgroundColor(this.getActivity()
					.getResources().getColor(R.color.actionbarcolor));
			auditingTaskButton.setBackgroundColor(this.getActivity()
					.getResources().getColor(R.color.taskbtncolor));
			submittedTaskButton.setTextColor(this.getActivity().getResources()
					.getColor(R.color.white));
			auditingTaskButton.setTextColor(this.getActivity().getResources()
					.getColor(R.color.black));
			FragmentTransaction transaction1 = fragmentManager
					.beginTransaction();
			transaction1.replace(R.id.myfragcontent, submittedFragment);
			transaction1.commit();
			break;
		case R.id.auditingTaskButton:
			auditingTaskButton.setBackgroundColor(this.getActivity()
					.getResources().getColor(R.color.actionbarcolor));
			submittedTaskButton.setBackgroundColor(this.getActivity()
					.getResources().getColor(R.color.taskbtncolor));
			submittedTaskButton.setTextColor(this.getActivity().getResources()
					.getColor(R.color.black));
			auditingTaskButton.setTextColor(this.getActivity().getResources()
					.getColor(R.color.white));
			FragmentTransaction transaction2 = fragmentManager
					.beginTransaction();
			transaction2.replace(R.id.myfragcontent, refusedFragment);
			transaction2.commit();
			break;
		}
	}

}
